<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
	<head>
		<jsp:include page="../inc_min.jsp"></jsp:include>
		<link rel="stylesheet" href="${ctx}/css/page.css"/>
		<link rel="stylesheet" href="${ctx}/css/iconfont.css"/>
		<title>订单管理-合同订单管理</title>
		<script type="text/javascript">
		var msgTime;
		var msgStatus;
		//消息提醒
		function getInformation(){
			$.ajax({
				type:"post",
				url:"${ctx}/msg/message",
				success:function(data){
					//console.log(data);
					for(var i=0;i<data.obj.length;i++){
						var prefix=data.obj[i];
							if(prefix.type == 5){
								msgTime = prefix.startTime;
								msgStatus = prefix.status;
						}
					}
					getInfoCount();
				},
				error:function(msg){
					layer.alert("请检查您的网络连接，然后重试！");
				}
			});
		};
		function getInfoCount(){
			$.ajax({
				type:"get",
				url:"${ctx}/nporder/selectStatus?lastLoginTime="+msgTime,
				success:function(data){
					$("#auditCount").html("("+data+")");
				},
				error:function(msg){
					layer.alert("请检查您的网络连接，然后重试！");
				}
			});
		};
        var pageNum = 1;
		$(function(){
			//状态背景文字切换
			$(".listArg").click(function(){
				$(".listArg").css({
					"background": "#f1f1f1",
					"color": "black"
				});
				$(this).css({
					"background": "#34c0e3",
					"color": "#FFFFFF"
				});
				var conStatus=$(this).find("span").attr('id');
				getAjax(conStatus);
			});
			getInformation();
            getAjax(-1);
			//点击查询 重新加载列表
			$("#query").click(function(){
				//出发到达城市清空处理
				alsoempty($("#homecity_name"),$("#_startCity"));
				alsoempty($("#getcity_name"),$("#_endCity"));
				//获取参数
				var conNo=$("#conNo").val();//合同号
				var pssconNo=$("#pssconNo").val();//外部合同号
				var conStatus=$("#conStatus").combobox("getValue"); //状态
				var deptAirportCode=$("#startCity").val(); //出发机场三字码
				var arrAirportCode=$("#arrCity").val(); //   到达机场三字码
 				//console.log(conNo+","+pssconNo+','+conStatus+','+deptAirportCode+','+arrAirportCode);

				if(typeof(deptAirportCode) == 'undefined'){
					deptAirportCode = "";
				}
				if(typeof(arrAirportCode) == 'undefined'){
					arrAirportCode = "";
				}
                getAjax();
			});
			//点击全部按钮时
			$("#-1").click(function(){
				$('#ticketTable').datagrid('load',{});
			});
			//点击审核完成按钮
			$("#5").click(function(){
				$("#auditCount").html("(0)");
				$('#ticketTable').datagrid('load',{"msgStatus":msgStatus,"msgTime":msgTime,"temp":Math.random()});
			})
	});
        function getAjax(conStatus) {
            var pageSize = 20;
            var conNo=$("#conNo").val();
            var pssconNo=$("#pssconNo").val();
            var toStartAirportCode=$("#_startCity").val();
            var toEndAirportCode=$("#_endCity").val();
            var toStartDate=$("#_startTime").val();
            //发送ajax请求  根据参数返回值
            if(typeof(toStartAirportCode) == 'undefined'){
                toStartAirportCode = "";
            }
            if(typeof(toEndAirportCode) == 'undefined'){
                toEndAirportCode = "";
            }
            $.get("${ctx}/search/pltm_contractList?conNo="
                    +conNo+"&pssconNo="
                    +pssconNo+"&conStatus="
                    +conStatus+"&deptAirportCode="
                    +toStartAirportCode+"&arrAirportCode="
                    +toEndAirportCode+"&toStartDate=&temp="
                    +Math.random()+"&page="
                    +pageNum+"&rows="
                    +pageSize+"&msgTime=${message.startTime}"+"&msgStatus=${message.status}",function(data){
                $('table tbody').empty();
                var str = "";
                for(var i=0;i<data.list.length;i++){
                    var obj = data.list[i];
                   // var tablebutton = "";

                   //查看详情操作
                    var time=obj.payOverTime;
                   	if(time == null || time == undefined){
                   		time="";
                   	}else{
                   		time=time.replace(" ","=");
                   	};
                    var moredetail='<i class="icon iconfont" title="详情" onclick=LookDetail("'+obj.conNo+'","'+obj.conStatus+'","'+time+'")>&#xe62d;</i>';
                    if(obj.conStatus==2){  
                        //待支付状态时  显示倒计时
                        var timeId = "time"+obj.conNo;
						var time = obj.seconds;
						if(time>0){
							 var timer_rt = window.setInterval("GetRTime("+time+",'"+timeId+"')", 1000);
						};
						 timeOut='<span style="color:#ff8800;">'+CommonConverter.toContractStatusStr(obj.conStatus)+'</span><img src="${ctx}/image/delay_out.png" style="vertical-align:middle">'+
						'<br/>剩余保留时间：<span id="'+timeId+'"></span>';
                    }else{
                    	timeOut=CommonConverter.toContractStatusStr(obj.conStatus);
                    };
                    str+="<tr height='38px' class='reBorder'>"
                    str+="    <td width='246px' align='center'>合同号："+obj.conNo+"</td>"
                    str+="    <td width='939px' align='left' colspan='6'>外部合同号："+obj.pssConNo+"</td>"
                    str+="    <td width='117px' align='center'>"+moredetail+"</td>"
                    str+="</tr>"
                    str+="<tr height='90px'>"
                    str+="   <td width='208px' style='color:#444e50' align='right'>"
                    str+=       obj.deptAirport + "("+obj.deptAirportCode+")"
                    str+="    </td>"
                    str+="    <td width='165px' align='center'>"
                    str+="    <img src='${ctx}/image/flightQuery/dancheng.png'>"
                    str+="    </td>"
                    str+="    <td width='208px' style='color:#444e50'>"
                    str+=       obj.arrAirport + "("+obj.arrAirportCode+")"
                    str+="    </td>"
                    str+="    <td width='88px' align='center' style='color:#444e50'>"+obj.productList.substring(0,obj.productList.length-1)+"</td>"
                    str+="   <td width='86px' align='center' style='color:#e2615c'>"+obj.seatCount+"</td>"
                    str+="   <td width='96px' align='center' style='color:#23b9dc'>"+obj.supplierName+"</td>"
                    str+="    <td width='151px' >"
                    str+="    <span style='color:#23b9dc;margin-left:50px;'>"+obj.buyerName+"</span><br/>"
                    str+="    <span style='margin-left:50px;'>"+CommonConverter.toEmptyString(obj.contact)+"</span><br/>"
                    str+="    <span style='margin-left:50px;'>"+CommonConverter.toEmptyString(obj.mobile)+"</span>"
                    str+="    </td>"
                    str+="    <td width='139px' align='center' style='color:#e2615c'>"
                    str+=timeOut;
                    str+="    </td>"
                    str+="</tr>"
                }
                $('#tb').append(str);
                //显示分页
                layui.use(['laypage', 'layer'], function(){
                    var laypage = layui.laypage;
                    laypage({
                        cont: 'pager'
                        ,pages: data.pages //得到总页数 //总页数
                        ,groups: 5 //连续显示分页数
                        ,skin: '#1E9FFF'
                        ,curr : pageNum
                        ,jump: function(obj,first){
                            if(!first){
                                pageNum = obj.curr;
                                getajax();
                            }
                        }
                    });
                });
            })
        }
	//查看日志
		function CheckLog(conNo){
			//alert(conNo);
			layer.open({
				type: 2,
				title: ['合同日志','background-color:#00B2EE; color:#fff;'],
				shadeClose: true,
				shade: 0.3,
				yes: function(index, layero) {
					layer.close(index);
				},
				btn2: function(index, layero) {
					//取消的回调
				},
				area: ['800px', '600px'],
				content: ['${ctx}/np/contractLog?conNo='+conNo],  //iframe的url，no代表不显示滚动条
				success: function(layero, index){
					// layer.full(index);
				},
				end:function(){
					// localtion.reload();
				}
			});
		}
		//查看详情
		function LookDetail(conNo,conStatus,paymentOverTime){
			window.location.href='${ctx}/np/contractDetailForPlatform?conNo='+conNo+'&conStatus='+conStatus+'&paymentOverTime='+paymentOverTime;

		};
		//如果为空  对应的文本框为空
		function alsoempty(a,b){
			if(a.val() == "中文/拼音"){
				b.val("");
			};
		};
		</script>
	</head>
	<body>
    <jsp:include page="../head.jsp"></jsp:include>
		<div class="content">
			<ul class="list">
					<li>
						合同号：
						<input type="text" id="conNo" style="width:150px"/>
					</li>
					<li>
						外部合同号：
						<input type="text" id="pssconNo" class="textbox"  style="width:150px;"/>
					</li>
					<li>出发城市：
						<input type="text" class="textbox" value="" size="15" id="homecity_name" name="homecity_name" style="width:150px;" mod="address|notice" mod_address_source="hotel" mod_address_suggest="" mod_address_reference="startCity" mod_notice_tip="中文/拼音" />
						<input id="startCity" name="startCity" type="hidden" value="" />
						</li>
						<li>
							到达城市：
							<input type="text" class="textbox" value="" size="15" id="getcity_name" name="getcity_name" style="width:150px;" mod="address|notice" mod_address_source="hotel"  mod_address_reference="arrCity" mod_notice_tip="中文/拼音" />
							<input id="arrCity" name="arrCity" type="hidden" value="" />
						</li>
						<li class="right">
							<input type="button" value="查询" class="mynewBtn" id="query"/>
						</li>
				</ul>
				<ul class="list conditionList">
					<li>状态：</li>
					<li class="listArg allStatus">
						<span id="-1" />全部</span>
					</li>
					<li class="listArg">
						<span id="1">待审核<span></span></a>
					</li>
					<li class="listArg">
						<span id="2">待支付<span></span></a>
					</li>
					<li class="listArg">
						<span id="3">押金已收<span></span></a>
					</li>
					<li class="listArg">
						<span id="4">合同中止<span></span></a>
					</li>
					<li class="listArg">
						<span id="5" >合同完成<span id="auditCount"></span></a>
					</li>
					<li class="listArg">
						<span id="6">合同退回<span></span></a>
					</li>
					<li class="listArg">
						<span id="7">合同取消<span></span></a>
					</li>
				</ul>
			<!-- <table id="ticketTable" class="easyui-datagrid" data-options="border:false"></table> -->
			<table class="conTable" >
				<thead>
					<tr height="38px" >
						<td width="226px" align="right">出发</td>
						<td width="86px" align="center">&nbsp;&nbsp;&nbsp;</td>
						<td width="204px" align="left">到达</td>
						<td width="216px" align="center">产品列表</td>
						<td width="172px" align="center">押金金额</td>
						<td width="122px" align="center">卖家信息</td>
						<td width="160px" align="center">买家信息</td>
						<td width="117px" align="center">状态
						</td>
					</tr>
				</thead>
				<tbody id="tb">
				</tbody>
			</table>
            <!-- 分页 -->
            <div id="pager" class="divBox"></div>
		</div>




<script type="text/javascript" src="${ctx }/jslib/airport/fixdiv.js"></script>
<script type="text/javascript" src="${ctx }/jslib/airport/address.js"></script>
<script type="text/javascript">

//定义参数可返回距 1970 年 1 月 1 日之间的毫秒数
function GetRTime(time,obj){
	//定义方法
	var startTime = new Date(time);
	//调用置指定时间的毫秒字段
	var EndTime=startTime.getTime();
    var NowTime = new Date();
    //定义参数可返回当天的日期和时间
    var nMS = EndTime - NowTime.getTime();
    //定义参数 EndTime减去NowTime参数获得返回距 1970 年 1 月 1 日之间的毫秒数
    var nD = Math.floor(nMS/(1000 * 60 * 60 * 24));
    //定义参数 获得天数
    var nH = Math.floor(nMS/(1000*60*60)) % 24;
    //定义参数 获得小时
    var nM = Math.floor(nMS/(1000*60)) % 60;
    //定义参数 获得分钟
    var nS = Math.floor(nMS/1000) % 60;
	if(nH < 10){nH = "0"+nH;}
	if(nM < 10){nM = "0"+nM;}
	if(nS < 10){nS = "0"+nS;}
    //定义参数 获得秒钟
    if (nMS > 0){
    //如果秒钟大于0
	   var str = nD+"天"+nH+"时"+nM+"分"+nS+"秒";
       //显示秒钟
	   $("#"+obj).html(str);
    }
};

</script>
    <jsp:include page="../footer.jsp"></jsp:include>
</body>
</html>